package com.tsunami.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;

/**
 * @author lx
 * @date 2021-06-10 18:01
 */
public class MybatisPlusConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor page = new MybatisPlusInterceptor();
        // 分页插件
        page.addInnerInterceptor(paginationInnerInterceptor());
        return page;
    }

    /**
     * 分页插件，自动识别数据库类型
     */
    private InnerInterceptor paginationInnerInterceptor() {
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        // 设置数据库类型为mysql
        paginationInnerInterceptor.setDbType(DbType.MYSQL);
        // 设置最大单页限制数量，默认 500 条，-1 不受限制
        paginationInnerInterceptor.setMaxLimit(-1L);
        return paginationInnerInterceptor;
    }

/*
  TenantLineInnerInterceptor 多租户插件
  https://baomidou.com/guide/interceptor-tenant-line.html
  DynamicTableNameInnerInterceptor 动态表名插件
  https://baomidou.com/guide/interceptor-dynamic-table-name.html
 */
}
